package com.ych.spring.service.impl;

import com.ych.spring.dao.BookDao;
import com.ych.spring.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.concurrent.TimeUnit;

/**
 * @author yangchenghao
 */
@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BookDao bookDao;

    @Override
//    @Transactional(timeout = 3,noRollbackFor = ArithmeticException.class,propagation = Propagation.REQUIRES_NEW)
    public void buyBookById(Integer bookId, Integer userId) {
        int price = bookDao.getPriceById(bookId);
        bookDao.updateStock(bookId);
        bookDao.updateBalance(userId, price);
    }
}
